/**
 * ConsoleWriter.java
 * @author: liuex
 * 2008-1-7 ����11:56:49
 *
 * note: 
 */
package org.lex.swing.widgets.console;

import java.io.IOException;
import java.io.Writer;

class ConsoleWriter extends Writer {
	static abstract class Printer {
		protected IConsole console = null;

		Printer(IConsole console) {
			this.console = console;
		}

		abstract IConsole print(Object o);
	}

	private Printer printer = null;

	public ConsoleWriter(Printer printer) {
		this.printer = printer;
	}

	@Override
	public ConsoleWriter append(char c) {
		printer.print(c);
		return this;
	}

	@Override
	public ConsoleWriter append(CharSequence csq, int start, int end) {
		printer.print(csq.subSequence(start, end));
		return this;
	}

	@Override
	public ConsoleWriter append(CharSequence csq) {
		printer.print(csq);
		return this;
	}

	@Override
	public void close() {
	}

	@Override
	public void flush() {
	}

	@Override
	public void write(char[] cbuf, int off, int len) {
		printer.print(new String(cbuf, off, len));
	}

	@Override
	public void write(char[] cbuf) {
		this.write(cbuf, 0, cbuf.length);
	}

	@Override
	public void write(int c) {
		printer.print((char) c);
	}

	@Override
	public void write(String str, int off, int len) {
		printer.print(str.substring(off, off + len));
	}

	@Override
	public void write(String str) throws IOException {
		printer.print(str);
	}
}